//
//  LGFontSettingController.m
//  微博
//
//  Created by MS on 15-12-27.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGFontSettingController.h"
#import "BasicSetting.h"
@interface LGFontSettingController ()
@property (nonatomic,strong) LGCheckItem * cheakItem;
@end

@implementation LGFontSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpGroup0];
}

-(void) setUpGroup0
{
    LGCheckItem * large = [LGCheckItem itemWithTitle:@"大"];
    __weak typeof(self) weakSelf = self;
 
    large.option = ^(LGItem * item){
        [weakSelf seleItem:(LGCheckItem *)item];
    };
    
    LGCheckItem * middle = [LGCheckItem itemWithTitle:@"中"];

    middle.option = ^(LGItem * item){
        [weakSelf seleItem:(LGCheckItem *)item];
    };
    
    
    LGCheckItem * small = [LGCheckItem itemWithTitle:@"小"];
        small.option = ^(LGItem * item){
        [weakSelf seleItem:(LGCheckItem *)item];
    };
    
    LGGroups * group = [[LGGroups alloc] init];
    group.headerTitle = @"设置字体大小";
    group.items = @[large,middle,small];
    [self.groups addObject:group];
    
    [self setUpSize:middle];
}

-(void) seleItem:(LGCheckItem *)item
{
    _cheakItem.cheak = NO;
    item.cheak = YES;
    _cheakItem = item;
    
    [self.tableView reloadData];
    
    [LGUserDefaults setValue:item.title forKey:LGFontSizeKey];
    [LGUserDefaults synchronize];

    [[NSNotificationCenter defaultCenter] postNotificationName:LGFontSizeChangeNote object:nil];
    
}

-(void)setUpSize:(LGCheckItem *)item
{
   NSString * fontSize = [LGUserDefaults objectForKey:LGFontSizeKey];
    if (fontSize==nil) {
        [self seleItem:item];
        return;
    }
    for (LGGroups * group in self.groups) {
        for (LGCheckItem * item in group.items) {
            if ([item.title isEqualToString:fontSize]) {
                [self seleItem:item];
            }
        }
    }
    
}

-(void)dealloc
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
